home *** CD-ROM | disk | FTP | other *** search
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- /* */
- /* MADE - Macintosh Application Development Essentials */
- /* --------------------------------------------------- */
- /* (c) Sig Software, http://www.sigsoftware.com/ */
- /* */
- /* These files can only be used for experimental purposes. To obtain */
- /* fully commented code, source code for the functions in Essential */
- /* Extras.h and permission for usage in final projects, you must */
- /* purchase a license. See documentation for more information. */
- /* */
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- /* */
- /* Essential Errors.c */
- /* ------------------ */
- /* */
- /* Error checking, handling, reporting and assertion support. */
- /* */
- /* Version 1.0.0 - 10th November 1996 */
- /* Version 1.1.0 - 29th January 1998 - Updated for new Mac Header */
- /* Version 1.2.0 - 20th November 1998 - Avoids C/C++ warnings */
- /* Version 1.4.0 - 26th May 1999 - Contexts, hiding, new alert */
- /* */
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- #include "Essential Headers.h"
- #include "Essential Prototypes.h"
- #include <Sound.h>
-
- typedef struct HidingLink HidingLink;
-
- struct HidingLink {
- HidingLink *next;
- Error *keepError;
- };
-
- typedef struct ContextLink ContextLink;
-
- struct ContextLink {
- ContextLink *next;
- Str255 contextString;
- };
-
- HidingLink *firstHiding=0;
- ContextLink *firstContext=0;
-
- Boolean HideErrors(Error* keepError)
- {
- Error error;
- HidingLink *link;
-
- link=(HidingLink*)AllocPtr(&error, sizeof(HidingLink));
- _i(error)
- link->keepError=keepError;
-
- AddToLinkedList(&firstHiding, link, firstHiding);
-
- return true;
- _e
- return false;
- }
-
- void ShowErrors()
- {
- HidingLink *link;
-
- link=firstHiding;
- Assert(link);
- RemoveFromLinkedList(&firstHiding, link);
- DestroyPtr(link);
- }
-
- Boolean AddErrorContext(Str255 contextString)
- {
- Error error;
- ContextLink *link;
-
- link=(ContextLink*)AllocPtr(&error, sizeof(ContextLink));
- _i(error)
- BlockMove(contextString, link->contextString, 1+*contextString);
-
- AddToLinkedList(&firstContext, link, firstContext);
-
- return true;
- _e
- return false;
- }
-
- void RemoveErrorContext()
- {
- ContextLink *link;
-
- link=firstContext;
- Assert(link);
- RemoveFromLinkedList(&firstContext, link);
- DestroyPtr(link);
- }
-
- void TestError(Error error)
- {
- Str255 contextString, IDString, errorString, solutionString;
- short numString, totalStrings, compareError;
- Handle errorsResource;
- unsigned char *errorStrings, appendLen;
- HidingLink *hiding;
- ContextLink *context;
-
- if (error) {
-
- if (firstHiding) {
- hiding=firstHiding;
- while (hiding) {
- *(hiding->keepError)=error;
- hiding=hiding->next;
- }
-
- SysBeep(1);
-
- } else {
- NumToString(error, IDString);
-
- errorsResource=GetResource('Err2', 128);
- if (ResError() || errorsResource==0)
- SysBeep(1);
-
- else {
- errorStrings=(unsigned char*)*errorsResource;
- totalStrings=*((short*)errorStrings)++;
-
- for (numString=0; numString<totalStrings; numString++) {
- compareError=*((short*)errorStrings)++;
-
- if (compareError==error)
- BlockMove(errorStrings, errorString, *errorStrings+1);
-
- errorStrings+=*errorStrings+1;
-
- if (compareError==error) {
- BlockMove(errorStrings, solutionString, *errorStrings+1);
- goto stringFound;
- }
-
- errorStrings+=*errorStrings+1;
- }
-
- *errorString=0;
- *solutionString=0;
-
- stringFound:
- if (*errorString==0)
- GetIndString(errorString, 32765, 1);
- if (*solutionString==0)
- GetIndString(solutionString, 32765, 1);
-
- *contextString=0;
- context=firstContext;
- while (context) {
- appendLen=*(context->contextString);
- if (((int)*contextString+(int)appendLen)>255)
- appendLen=(unsigned char)(255-*contextString);
-
- BlockMove(context->contextString+1, contextString+*contextString+1, appendLen);
- *contextString+=appendLen;
-
- context=context->next;
- }
-
- ParamText(contextString, IDString, errorString, solutionString);
- SetCursor(&qd.arrow);
- Alert(32766, 0);
- }
- }
- }
- }
-
- Error TestResError(void* resource)
- {
- Error error;
-
- error=ResError();
- if (!error)
- if (resource==0L)
- error=resNotFound;
- TestError(error);
-
- return error;
- }
-
- Error TestMemError(void* pointer)
- {
- Error error;
-
- error=MemError();
- if (!error)
- if (pointer==0L)
- error=memFullErr;
- TestError(error);
-
- return error;
- }
-
- #if Project_Under_Development
-
- void HandleAssertFailure(char* file, char* date, int line)
- {
- Str255 fileString, dateString, lineString, memoryString;
- unsigned char *stringPtr;
-
- stringPtr=fileString+1;
- while (*file)
- *stringPtr++=(unsigned char)*file++;
- *fileString=(unsigned char)(stringPtr-fileString-2);
-
- stringPtr=dateString+1;
- while (*date)
- *stringPtr++=(unsigned char)*date++;
- *dateString=(unsigned char)(stringPtr-dateString-2);
-
- NumToString(line, lineString);
- NumToString(MaxBlock(), memoryString);
-
- ParamText(fileString, dateString, lineString, memoryString);
-
- SetCursor(&qd.arrow);
- switch (Alert(32767, 0)) {
- case 1:
- Debugger();
- break;
- case 2:
- ExitToShell();
- break;
- case 3:
- ExecutionBody();
- break;
- case 4:
- break;
- }
- }
-
- #endif
-